package cn.xfdzx.android.apps.shop.presenter;

import java.util.HashMap;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.AddAddressBeen;
import cn.xfdzx.android.apps.shop.bean.Qc_StoreBean;
import cn.xfdzx.android.apps.shop.bean.Qc_StoreListBean;
import cn.xfdzx.android.apps.shop.bean.Store_ruzhuBean;
import cn.xfdzx.android.apps.shop.contract.AddAddressContract;
import cn.xfdzx.android.apps.shop.contract.Qc_shopContract;
import cn.xfdzx.android.apps.shop.model.AddAddressModel;
import cn.xfdzx.android.apps.shop.model.Qc_shopModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author azheng
 * @date 2018/6/4.
 * Description：
 */
public class Qc_shopPresenter extends BasePresenter<Qc_shopContract.View> implements Qc_shopContract.Presenter {

    private Qc_shopContract.Model model;

    public Qc_shopPresenter() {
        model = new Qc_shopModel();
    }


    @Override
    public void getQcStoreInfor(String store_id, int type) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getStoreInfo(store_id,type)
                .compose(RxScheduler.<Qc_StoreBean>Flo_io_main())
                .as(mView.<Qc_StoreBean>bindAutoDispose())
                .subscribe(new Consumer<Qc_StoreBean>() {
                    @Override
                    public void accept(Qc_StoreBean bean) throws Exception {
                        mView.forQcStoreInfor(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void getQcStoreList(HashMap<String, Object> map) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getStoreList(map)
                .compose(RxScheduler.<Qc_StoreListBean>Flo_io_main())
                .as(mView.<Qc_StoreListBean>bindAutoDispose())
                .subscribe(new Consumer<Qc_StoreListBean>() {
                    @Override
                    public void accept(Qc_StoreListBean bean) throws Exception {
                        mView.forQcStoreList(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
